<template>
  <a-card style="position: relative;margin:0;border-radius:0px">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
<!--          <a-col :md="6" :sm="8">
            <a-form-item label="填报时间开始">
              <j-date
                style="width: 100%"
                v-model="model.fillInStartTime"
                :disabled="
                  stage == '05010' || stage == '05050' ? true : status === '9' || status === '2' ? true : false
                "
              ></j-date>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="填报时间结束">
              <j-date
                style="width: 100%"
                v-model="model.fillInEndTime"
                :disabled="
                  stage == '05010' || stage == '05050' ? true : status === '9' || status === '2' ? true : false
                "
              ></j-date>
            </a-form-item>
          </a-col>-->
          <a-col :md="6" :sm="8">
            <a-form-item label="覆盖资产（万元）">
              <a-input-number
                style="width: 100%"
                v-model="model.fgzc"
                :disabled="
                  stage == '05010' || stage == '05050' ? true : status === '9' || status === '2' ? true : false
                "
              ></a-input-number>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <div class="table-operator" v-if="stage !== '05010' && stage !== '05050' && stage !== '01010' && stage !== '01020' && stage !== '01030'">
              <a-button :disabled="status == '9' || status == '2'" type="primary" @click="save">保存 </a-button>
            </div>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
<!--    <div style="margin-top: 20px" class="table-operator" v-if="stage !== '05010' && stage !== '05050' && stage !== '01010' && stage !== '01020' && stage !== '01030'">
      <a-button :disabled="status == '9' || status == '2'" type="primary" @click="save">保存 </a-button>

      <a-popconfirm
        v-permission="['10070']"
        :disabled="status == '9' || status == '2'"
        title="附件是否全部上传?"
        @confirm="() => showConfirm()"
      >
        <a-button v-permission="['10070']" :disabled="status == '9' || status == '2'" type="primary">
          提交审核
        </a-button>
      </a-popconfirm>

      <a-button :disabled="status !== '2'" v-permission="['10080']" @click="setApproveReason('9')">
        同意
      </a-button>
      <a-button :disabled="status !== '2'" v-permission="['10080']" type="danger" @click="setApproveReason('1')">
        拒绝
      </a-button>
      <a-button @click="showShjl" style="margin-top:10px">审核记录</a-button>
    </div>-->
    <div class="ant-alert ant-alert-info" style="margin: 16px 0;">
      <span>资料列表</span>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns1"
        :dataSource="dataSource1"
        :pagination="false"
        :loading="loading"
      >
        <span slot="fileName" slot-scope="text, record">
          <a style="text-decoration: underline" @click="handleDownloadFile(record.fileUrl)">{{ record.fileName }}</a>
        </span>
        <span slot="actionName">
          <a-button
            v-if="stage !== '05010' && stage !== '05050'"
            v-permission="['10070']"
            size="small"
            @click="addTableData('1')"
            type="primary"
            icon="plus"
            >新增
          </a-button>
          <span v-else>操作</span>
        </span>
        <span slot="action" slot-scope="text, record" v-if="stage !== '05010' && stage !== '05050'">
          <a @click="addTableData(record)">添加下级</a>
          <a-divider type="vertical" />
          <a @click="editTableData(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => deleteData(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
        <span slot="action" slot-scope="text, record" v-else>
          <a-button type="link" @click="handleCheck(record, '查看')">查看</a-button>
        </span>
      </a-table>
    </div>
    <!-- 操作记录 -->
    <div class="ant-alert ant-alert-info" style="margin: 16px 0;">
      <span>操作记录</span>
    </div>
    <!-- table区域-end -->
    <a-table
      ref="table"
      size="middle"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="dataSource"
      :pagination="ipagination"
      :loading="loading"
      @change="handleTableChange"
    >
    </a-table>
    <ModelForm ref="modalForm" :id="id" :stage="stage" @ok="uploadData"></ModelForm>
    <SelectApprove ref="approver" :id="id" @submitData="handleSubmit"></SelectApprove>
    <SetReason ref="setReason" @approveReason="approveData"></SetReason>
    <shjlModal ref="shjlModal" :id="id" :typeId="typeId" :apiUrl="url.applyLog"></shjlModal>
  </a-card>
</template>
<script>
import { getAction, deleteAction, postAction } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { butStatus } from '../public/butStatus'
import ModelForm from './ModelForm'
import columns1 from './indexColumns'
import columns from './workColumns'
import SelectApprove from '../public/SelectApprover'
import SetReason from '../public/SetReason'
import shjlModal from '../shjlModal'

export default {
  props: ['id', 'stage', 'type'],
  name: 'bsjdwzl',
  mixins: [JeecgListMixin, butStatus],
  components: {
    ModelForm,
    SetReason,
    SelectApprove,
    shjlModal
  },
  data() {
    return {
      model: {},
      queryParam: {
        model: 'zl',
        proId: this.id,
        stage: this.stage,
        typeId: this.type
      },
      typeId: this.type,
      loading: false,
      // 表头
      columns1: columns1(this),
      columns: columns(this),
      dataSource1: [],
      url: {
        list1: '/sjxmzygl/sjWorkBsjdwzl/queryBsjdwzlInfoNoPage',
        list: '/sjxmzygl/sjWorkLog/queryWorkLogList',
        delete: '/sjxmzygl/sjWorkBsjdwzl/remove',
        save: '/sjxmzygl/sjWorkBsjdwzl/addFgzc',
        submit: '/sjxmzygl/sjWorkUsers/submitAudit',
        approve: '/sjxmzygl/sjWorkUsers/zyApplyCommit',
        applyLog: '/sjxmzygl/sjWorkApplyLog/queryApplyLog',
        getTop: '/sjxmzygl/sjWorkBsjdwzl/getZl'
      }
    }
  },
  created() {
    this.getTopData()
    this.list1()
  },
  methods: {
    showConfirm() {
      if (this.dataSource1.length == 0) {
        this.$message.warning('请添加数据!')
        return
      }
      this.$refs.approver.show()
    },
    // 获取头部信息
    getTopData() {
      getAction(this.url.getTop, { proId: this.id }).then(res => {
        if (res.success && res.result != null) {
          this.model = res.result
        }
      })
    },
    save() {
      /*if (
        this.model.fillInStartTime === null ||
        this.model.fillInStartTime === undefined ||
        this.model.fillInStartTime === ''
      ) {
        this.$message.warning('请选择填报开始日期!')
        return
      }
      if (
        this.model.fillInEndTime === null ||
        this.model.fillInEndTime === undefined ||
        this.model.fillInEndTime === ''
      ) {
        this.$message.warning('请选择填报结束日期!')
        return
      }*/
      if (this.model.fgzc === null || this.model.fgzc === undefined || this.model.fgzc === '') {
        this.$message.warning('请填写覆盖资产!')
        return
      }
      postAction(this.url.save, {
        ...this.model,
        proId: this.id
      }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.error(res.message)
        }
      })
    },
    // 新增或调增计划项目
    addList(record) {
      if (record.pid) {
        if (record.id) {
          this.dataSource[record.index].children.push({ name: null, fileName: null, pid: record.pid })
        } else {
          this.$message.error('请先保存上级信息')
        }
      } else {
        this.dataSource.push({ name: null, fileName: null, pid: '0' })
      }
    },
    handleDownloadFile(fileUrl) {
      this.$message.success('正在下载，请稍等！')
      let url = `${window._CONFIG['domianURL']}/sys/common/download${fileUrl}`
      window.open(url, '_blank')
    },
    deleteData(id) {
      deleteAction(this.url.delete, { id: id }).then(res => {
        if (res.success) {
          this.$message.success(res.message)
          this.list1()
          this.loadData()
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    list1() {
      getAction(this.url.list1, this.queryParam).then(res => {
        if (res.success) {
          this.dataSource1 = res.result.records || res.result
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    addTableData(record) {
      this.$refs.modalForm.disableSubmit = false
      this.$refs.modalForm.add(record)
    },
    editTableData(record) {
      this.$refs.modalForm.disableSubmit = false
      this.$refs.modalForm.edit(record)
    },
    uploadData() {
      this.list1()
      this.loadData()
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
<style lang="less" scoped>
.table-page-search-wrapper {
  .ant-form-inline {
    .ant-form-item {
      margin-bottom: 0;
    }
  }
}

.ant-row {
  height: 100%;

  .ant-col {
    height: 100%;

    .ant-card {
      height: 100%;

      /deep/ .ant-card-body {
        padding: 15px;
      }
    }
  }
}

.funBtn {
  padding: 0 10px;
  margin-left: 10px;
}
</style>
